(defpackage :com.qingluan.spam
  (:use :common-lisp ))
(defparameter *max-ham-score* 0.4)
(defparameter *min-spam-score* 0.6)


(defun classify (Text)
  (classification (score (extract-features Text))))


(defun classification (score)
  (cond 
    ((>=  *min-spam-score* ) 'spam)
    ((<= *max-ham-score* )  'ham)
    (t 'unknow)))

(defclass word-fearture ()
  ((word
    :initarg :word
    :accessor word
    :initform  (error "Must a  word ")
    :documentation  "feature represent")
   (spam-count 
    :initarg :spam-count 
    :accessor spam-count 
    :initform 0
    :documentation "numbers of spams ")
   (ham-count 
    :initarg :ham-count
    :accessor ham-count
    :initform 0
    :documentation "numbers of hams")))

(defvar *feature-database* (make-hash-table :test #'equal))
(defun clear-feature-database()
  (setf *feature-database* (make-hash-table :test #'equal)))
(defun intern-feature (word)
  (or (gethash word *feature* )
      (setf (gethash word *feature* ) (make-instance 'word-feature :word word))))
